import React, { Component } from "react"
import {
    WebView,
    View
} from "react-native"
import Nav from 'src/components/navBar'
import navigationhelper from 'src/components/navigationhelper'

export default class index extends Component {
    constructor(props) {
        super(props)
        const url = this.props.navigation.getParam("url")
        const title = this.props.navigation.getParam("title")
        this.state = {
            canGoBack: false,
            url: url,
            title: title
        }
    }

    refresh = () => {
        this.webview.reload()
    }

    render() {
        console.log(this.state.url)
        return (
            <View style={{ flex: 1 }}>
                <Nav title={this.state.title}
                back={()=>{navigationhelper.goBack()}} 
                />
                <WebView
                    onNavigationStateChange={(event) => {
                        this.setState({
                            canGoBack: event.canGoBack
                        })
                    }}
                    mixedContentMode='always'
                    javaScriptEnabled={true}
                    renderError={(e) => {
                        if (e === 'WebKitErrorDomain') {
                            return
                        }
                    }}
                    ref={ref => {
                        this.webview = ref
                    }}
                    source={{ uri:this.state.url}}
                />
            </View>
        )
    }
}
